var RoomDao = require("../dao/RoomDao");
// 房间控制器
module.exports = {
    // 进入房间
    enterRoom:function (app, cb) {
        RoomDao.getNotFullRoom(app, (err, result)=>{
            if (err) {
                cb(err);
            } else if (result) {
                result.playerCount ++;
                result.players = [];

                cb(err, result);
            } else {
                RoomDao.addRoom(app, ()=>{
                    RoomDao.getNotFullRoom(app, (err, result)=>{
                        if (err) {
                            cb(err);
                        } else if (result) {
                            cb(err, result);
                        } else {
                            cb("error no room");
                        }
                    });
                });
            }
        });
    },
    // 退出房间
    exitRoom:function (app, cb) {

    },
}